<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>数据填报</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function submitForm(){                                      //子窗体页面的保存数据方法 通过ajax
			var flag = false;
            if($("#inputForm").valid()){
                var url = "${ctx}/ins/insData/save";
                $.ajax({
                    type: 'POST',
                    url : url,
                    async:false,
                    data: $('#inputForm').serialize(),             //获取表单数据
                    success : function(data) {
                    	    flag = true;
                            alert("保存成功");
                            parent.$('#btn').click();
                            parent.$.jBox.close(true);
                    },
                    error : function(data){
                    	alertx("无权限");
                    }
                });
            }
            return flag;
        }
	</script>
</head>
<body>
	<br/>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/ins/insLog/form?id=${insLog.id}&save=after">修改后</a></li>
		<li class="active"><a href="${ctx}/ins/insLog/form?id=${insLog.id}&save=before">修改前</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="insData" action="${ctx}/ins/insData/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<input type="hidden" value="${insData.table.id}" name="table.id"/>
		<sys:message content="${message}"/>		
		<c:forEach items="${insData.datas}" var="dataLink" varStatus="status">
			<div class="control-group">
				<label class="control-label">${dataLink.field.name}：</label>
				<div class="controls">
					<c:choose>
						<c:when test="${dataLink.field.type==2}">
							<input disabled="disabled" type="text" class="input-xlarge number" value="${empty dataLink.value?dataLink.field.defaultValue:dataLink.value}" name="datas[${status.index}].value"/>
						</c:when>
						<c:when test="${dataLink.field.type==3}">
							<input disabled="disabled" name="datas[${status.index}].value" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
							value="${empty dataLink.value?dataLink.field.defaultValue:dataLink.value}" pattern="yyyy-MM-dd HH:mm:ss"
							onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
						</c:when>
						<c:when test="${dataLink.field.type==4}">
							<input disabled="disabled" name="datas[${status.index}].value" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
							value="${empty dataLink.value?dataLink.field.defaultValue:dataLink.value}" pattern="yyyy-MM-dd"
							onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
						</c:when>
						<c:otherwise>
							<input disabled="disabled" type="text" class="input-xlarge" value="${empty dataLink.value?dataLink.field.defaultValue:dataLink.value}" name="datas[${status.index}].value"/>
						</c:otherwise>
					</c:choose>
					<input type="hidden" value="${insData.table.id}" name="datas[${status.index}].table.id"/>
					<input type="hidden" value="${insData.id}" name="datas[${status.index}].data.id"/>
					<input type="hidden" value="${dataLink.field.id}" name="datas[${status.index}].field.id"/>
					<input type="hidden" value="${dataLink.field.name}" name="datas[${status.index}].field.name"/>
				</div>
			</div>
		</c:forEach>
	</form:form>
</body>
</html>